package com.yupin.main;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

import org.lobobrowser.gui.BrowserPanel;
import org.lobobrowser.main.PlatformInit;

import com.yuping.service.IMBrowser;

public class MyFrame extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static void main(String[] args) throws Exception {
		// Initialize logging.
		PlatformInit.getInstance().initLogging(false);
		// This step is necessary for extensions to work:
		PlatformInit.getInstance().init(false, false);
		
		// Create frame with a specific size.
		IMBrowser.getInstance();
	
	}

	public MyFrame() throws Exception {
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setSize(1000, 800);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new BorderLayout());
		   JPanel panel1=new JPanel();
		   this.add(panel1,BorderLayout.SOUTH);
		   panel1.setLayout(new FlowLayout());
		   //JLabel label1 = new JLabel(new ImageIcon("back.png"));
	      JButton buttonMail=new JButton("Mail");
	      JButton buttonAbout=new JButton("About");
	      
	      
	      //buttonAbout.setSize(1000, 1000);
	       panel1.add(buttonMail);
	       buttonMail.setSize(100, 100);
	       panel1.add(buttonAbout);
	       
	       buttonAbout.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "Potato & Nathan");
				
			}
		});
	       
	       buttonMail.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				
				JFrame tempFrame = new JFrame("Gmail Sender");

				tempFrame.setBounds(400, 400, 500, 400);
				tempFrame.setVisible(true);
				tempFrame.add(new MailPanel());
				
			}
		});
	       
	       

	       
		this.setTitle("Yupin");
		final BrowserPanel bp = new BrowserPanel();
		bp.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(EtchedBorder.RAISED), "Yupin browser"));
		bp.navigate("http://www.baidu.com");
		this.getContentPane().add(bp);
		
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				// This needs to be called in order
				// to inform extensions about the
				// window closing.
				bp.windowClosing();
			}
		});
	}
}